/*
Copyright (c) 2009, Young Digital Planet SA
All rights reserved.

* Redistribution and use in source and binary forms, with or without 
  modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this 
  list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, 
  this list of conditions and the following disclaimer in the documentation 
  and/or other materials provided with the distribution.
* Neither the name of the Young Digital Planet SA nor the names of its 
  contributors may be used to endorse or promote products derived from this 
  software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
*/
package pl.ydp.jobs
{
	/**
	 * Event dispatched when job started.  
	 * @eventType pl.ydp.jobs.YJobs.JOB_STARTED
	 */
	[Event(name="jobStarted",type="flash.events.Event")]
	/**
	 * Event dispatched when work is done
	 * @eventType pl.ydp.jobs.YJobs.JOB_DONE
	 */
	[Event(name="jobDone",type="pl.ydp.jobs.events.DoneEvent")]
	/**
	 * Event dispatched when work was cancelled (from world)
	 * @eventType pl.ydp.jobs.YJobs.JOB_CANCELLED
	 */
	[Event(name="jobCancelled",type="flash.events.Event")]
	/**
	 * Fired when job bart is added to this job.
	 * @see #addPart()
	 * @eventType pl.ydp.jobs.events.JobForkEvent.JOB_ADD_PART
	 */
	[Event(name="jobAddPart",type="pl.ydp.jobs.events.JobForkEvent")]
	/**
	 * Allows worker to send information to the word
	 * about current job and receive information if job can
	 * continue.
	 */
	public interface IJobControl extends IJobContainer
	{
		/**
		 * Mark job as started.
		 * @see #event:jobStarted
		 */
		function start():void;
		
		/**
		 * Set job total work. Don't include added partial jobs here. 
		 * @param total total work units. use special variable YJobs.WORK_UNKNOWN
		 * if u can't determine total amount of work.
		 * @see pl.ydp.jobs.YJobs#WORK_UNKNOWN
		 */
		function set totalWork( total:int ):void;
		
		/**
		 * Set amount of work already done. Don't include added partial
		 * jobs here.
		 * @param worked how many units of totalWork are done.
		 * @see #step()
		 */
		function set worked( worked:int ):void;
		
		/**
		 * Marks job as done. No further calls are allowed. When jobs has 
		 * parts, it cannot be done before it's parts are done.
		 * @param success additional information if job finished with success.
		 * false should be set when work was cancelled.
		 * @see #event:jobDone
		 */
		function done( success:Boolean = true ):void;
		
		/**
		 * Increases worked value with given step
		 * @param step amount to increase worked, default 1
		 * @see #worked()
		 */
		function step( step:uint = 1 ):void;
		
		/**
		 * Get information from the world if job is cancelled?
		 * @see #event:jobCancelled
		 */
		function get isCancelled():Boolean;
		
		/**
		 * Add jobs sub-part, some jobs are split into many stage. Add these
		 * stages with this function. This creates logical hierarchy of jobs
		 * and allows framework to auto-calculate values od totalWork and 
		 * worked. Jobs can be added to multiple container's - some operations
		 * may take part in multiple activities. 
		 * @param job this work separate part
		 * @see #totalWork()
		 * @see #worked()
		 * @see #done()
		 * @see #event:jobAddPart
		 */
		function addPart( job:IJobInfo ):void;
	}
}